#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <sys/mman.h>
#include <pthread.h>

static pthread_mutex_t *mptr;

void lock_init() {
	int fd;
	pthread_mutexattr_t mattr;

	fd = open("/dev/zero", O_RDWR, 0);
	mptr = mmap(0, sizeof(pthread_mutex_t), PROT_READ|PROT_WRITE, \
		MAP_SHARED, fd, 0);
	close(fd);

	pthread_mutexattr_init(&mattr);
	pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
	pthread_mutex_init(mptr, &mattr);
}

void lock_wait() {
	pthread_mutex_lock(mptr);
}

void lock_realse() {
	pthread_mutex_unlock(mptr);
}